----------- 
-- Author: Bojun Chen
-- Date: 2021-09-10 14:33:42
-- Desc: 基础视图
----------- 

local Time = Time
local BaseUIWinLife = BaseUIWinLife

local BaseView = class("BaseView", BaseUIWinLife)


function BaseView:ctor(config, gameObject, viewModel)
    self.config = config
    self.viewModel = viewModel
    self.gameObject = gameObject
    self.name = config.WINDOW_NAME
    self.bronTime = Time.realtimeSinceStartup
    self.gameObject.name = self.name
end


--[[
    @desc: 检测本界面是否已经超过缓存时间
    author:Bojun Chen
    time:2021-09-16 15:43:42
    @return: [true 超过缓存时间] [false 未超过缓存时间]
]]
function BaseView:CheckCacheTime()
    local checkTime = Time.realtimeSinceStartup - self.bronTime
    local endTime = self.config.Cache - checkTime
    return endTime < 0
end


--[[
    @desc: 注册事件
    author:Bojun Chen
    time:2021-09-16 15:31:33
    --@name: 数据名称
	--@callback: 数据改变时的回调
    @return:
]]
function BaseView:RegistField(name, callback)
    self.viewModel:RegistField(name, callback, self)
end

function BaseView:Init()
    self:OnInit()
    self.viewModel:Init()
end

function BaseView:Enable(...)
    self.gameObject:SetActive(true)

    self:OnEnable(...)
    self.viewModel:Enable(...)
end


function BaseView:Disable(...)
    self:OnDisable(...)
    self.viewModel:Disable(...)

    self.gameObject:SetActive(false)
end

function BaseView:Destroy()
    -- 销毁界面对象
    GameObject.Destroy(self.gameObject)
    self.gameObject = nil
    -- 销毁数据对象
    self.viewModel:Destory()
    self.viewModel = nil
    -- 销毁本身
    self:Destory()
end

function BaseView:OnInit()

end


function BaseView:OnEnable(...)
    
end


function BaseView:OnDisable(...)
    
end


function BaseView:OnDestroy()
    
end


return  BaseView